package com.basic.java.threads.daemon;

/**
 * 守护线程类
 * 创建时间：2022/4/19 21:35
 *
 * @author gejin
 */
// 上帝守护着你
public class TestDaemonThread {
    public static void main(String[] args) {
        God god = new God();
        You you = new You();

        // 把上帝线程设置成守护线程
        Thread threadGod = new Thread(god);
        threadGod.setDaemon(true);
        threadGod.start();

        // 然后到你了
        Thread threadYou = new Thread(you);
        threadYou.start();
    }
}

// 上帝是不会死的
class God implements Runnable {

    @Override
    public void run() {
        while (true) {
            System.out.println("上帝在守护着你！");
        }
    }
}

// 你，最多36500天就byebye了
class You implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 36500; i++) {
            System.out.println("你快乐的过着每一天");
        }
        System.out.println("=========GoodBye World=============");
    }
}
